package com.goods.controller.business;

import com.goods.business.service.SupplierService;
import com.goods.common.response.ResponseBean;
import com.goods.common.vo.business.SupplierVO;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;
import java.util.Map;

@RequestMapping("/business/supplier")
@RestController
public class SupplierController {

    @Resource
    private SupplierService supplierService;

    //查询
    @GetMapping("/findSupplierList")
    public ResponseBean findSupplierList(int pageNum, int pageSize, String name,String address,String contact){
        Map map = supplierService.findSupplierList(pageNum,pageSize,name,address,contact);
        return ResponseBean.success(map);
    }

    //添加
    @PostMapping("/add")
    public ResponseBean add(@RequestBody SupplierVO supplierVO){
        supplierService.add(supplierVO);
        return ResponseBean.success();
    }

    //通过id查询修改的对象
    @GetMapping("/edit/{id}")
    public ResponseBean edit(@PathVariable Long id){
        SupplierVO supplierVO = supplierService.edit(id);
        return ResponseBean.success(supplierVO);
    }

    //更新数据
    @PutMapping("/update/{id}")
    public ResponseBean update(@PathVariable Long id,@RequestBody SupplierVO supplierVO){
        supplierService.updateById(id,supplierVO);
        return ResponseBean.success();
    }

    //删除数据
    @DeleteMapping("delete/{id}")
    public ResponseBean deleteById(@PathVariable Long id){
        int num = supplierService.deleteById(id);
        if (num != 0){
            return ResponseBean.success();
        }else {
            return ResponseBean.error(num);
        }

    }

    //加载全部物资来源
    @GetMapping("/findAll")
    public ResponseBean findAll(){
        List<SupplierVO> supplierVOS = supplierService.findAll();
        return ResponseBean.success(supplierVOS);
    }

}
